package GUI;

import java.awt.event.ActionListener;

import javax.swing.JFormattedTextField;
import javax.swing.JList;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.text.MaskFormatter;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.text.ParseException;

import javax.swing.ListSelectionModel;
import javax.swing.border.EtchedBorder;

import Controllers.LoginController;

/**
 * The Class InitiateSaleGUI.
 * Boundary for sale initiation activity.
 */
public class InitiateSaleGUI extends AbstractPanelGUI {
	
	/** The date text field. */
	private JFormattedTextField dateTf;
	
	/** The period text field. */
	private JTextField periodTf;
	
	/** The ok button. */
	private JButton okButton;
	
	/** The back button. */
	private JButton btnBack;
	
	/** The marketing patters list. */
	private JList<String> MpList;
	/**
	 * Create the panel.
	 */
	public InitiateSaleGUI() {
	//	LoginController.mainWindow.setTitle("Initiate sale");
		setBackground(Color.ORANGE);
		initialize();

	}

	
	/* (non-Javadoc)
	 * @see GUI.AbstractPanelGUI#initialize()
	 */
	public void initialize() {
		setLayout(null);
		setSize(Width,Height);
		
		JLabel dateLb = new JLabel("Date:");
		dateLb.setForeground(new Color(0, 0, 0));
		dateLb.setFont(new Font("Tahoma", Font.PLAIN, 11));
		dateLb.setBounds(154, 204, 46, 14);
		add(dateLb);
		
		JLabel periodLb = new JLabel("Period:");
		periodLb.setForeground(new Color(0, 0, 0));
		periodLb.setFont(new Font("Tahoma", Font.PLAIN, 11));
		periodLb.setBounds(154, 254, 46, 14);
		add(periodLb);
		
	
	
	
		
		try {
			MaskFormatter date=new MaskFormatter("##/##/####");
			date.setPlaceholderCharacter('_');
			dateTf = new JFormattedTextField(date);
			dateTf.setBounds(210, 201, 151, 20);
			add(dateTf);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		periodTf = new JTextField();
		periodTf.setBounds(210, 251, 151, 20);
		add(periodTf);
		periodTf.setDocument(new JTextFieldLimit(10));
		
		okButton = new JButton("OK");
		okButton.setBounds(228, 294, 89, 23);
		add(okButton);
		
		btnBack = new JButton("Back");
		btnBack.setBounds(10, 337, 89, 23);
		add(btnBack);
		
		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(108, 44, 339, 130);
		add(scrollPane_1);
		
		MpList = new JList<String>();
		MpList.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		MpList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		MpList.setLocation(0, 52);
		scrollPane_1.setViewportView(MpList);
		MpList.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
		
		JLabel lblMarketingPattern = new JLabel("Marketing pattern:");
		lblMarketingPattern.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblMarketingPattern.setBounds(10, 98, 107, 14);
		add(lblMarketingPattern);
		
		JLabel lblMpid = new JLabel("MpId | Pid | ProductName | Age | LivingArea");
		lblMpid.setBounds(108, 30, 339, 14);
		add(lblMpid);
	}
	
	/**
	 * Adds action listener to the ok button.
	 *
	 * @param listener the listener
	 */
	public void addOKActionListener(ActionListener listener)
	{
		okButton.addActionListener(listener);
	}
	
	/**
	 * Adds action listener to the back button.
	 *
	 * @param listener the listener
	 */
	public void addBackActionListener(ActionListener listener)
	{
		btnBack.addActionListener(listener);
	}

	/**
	 * Gets the date text field.
	 *
	 * @return the date text field
	 */
	public JTextField getDateTf() {
		return dateTf;
	}


	/**
	 * Sets the date text field.
	 *
	 * @param dateTf the new date text field
	 */
	public void setDateTf(JFormattedTextField dateTf) {
		this.dateTf = dateTf;
	}


	/**
	 * Gets the period text field.
	 *
	 * @return the period text field
	 */
	public JTextField getPeriodTf() {
		return periodTf;
	}


	/**
	 * Sets the period text field.
	 *
	 * @param periodTf the new period text field
	 */
	public void setPeriodTf(JTextField periodTf) {
		this.periodTf = periodTf;
	}


	/**
	 * Gets the ok button.
	 *
	 * @return the ok button
	 */
	public JButton getOkButton() {
		return okButton;
	}


	/**
	 * Sets the ok button.
	 *
	 * @param okButton the new ok button
	 */
	public void setOkButton(JButton okButton) {
		this.okButton = okButton;
	}


	/**
	 * Gets the back button.
	 *
	 * @return the back button
	 */
	public JButton getBtnBack() {
		return btnBack;
	}


	/**
	 * Sets the back button.
	 *
	 * @param btnBack the new back button
	 */
	public void setBtnBack(JButton btnBack) {
		this.btnBack = btnBack;
	}


	/**
	 * Gets the marketing patterns list.
	 *
	 * @return the marketing patterns list
	 */
	public JList<String> getMpList() {
		return MpList;
	}


	/**
	 * Sets the marketing patterns list.
	 *
	 * @param mpList the new marketing patterns list
	 */
	public void setMpList(JList<String> mpList) {
		MpList = mpList;
	}
}
